/*
 * Copyright (C) 2010, Funcom AS, All Rights Reserved
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  @authors
 *  Svein Gunnar Larsen <sveingunnarlarsen@gmail.com>
 *  Erik Thune Lund <culex.eriklund@gmail.com>
 *  Michel Krohn-Dale <kronicz@gmail.com>
 */

package com.funcom.peeler;

import com.gibbon.jme.context.JmeContext;
import com.gibbon.jme.pass.Pass;
import com.gibbon.jme.pass.PassType;

import java.awt.*;

public class BuiPass extends Pass {

    protected Canvas sceneCanvas;
    protected BPRootNode sceneRoot;

    public BuiPass(Canvas canvas) {
        super(PassType.PRE_RENDER, "BananaUserInterface");

        sceneCanvas = canvas;
        sceneCanvas.createBufferStrategy(2);
        sceneRoot = new BPCanvasRootNode(canvas);
    }
    @Override
    public void runPass(JmeContext context) {
        doUpdate(context);
        doRender(context);
    }

    public Canvas getCanvas(){
        return sceneCanvas;
    }
    
    public BPRootNode getSceneRoot(){
        return sceneRoot;
    }
    @Override
    public void initPass(JmeContext context) {

    }

    @Override
    public void cleanPass(JmeContext context) {

    }

    public void doUpdate(JmeContext context) {
        sceneRoot.dispatchEvents();
    }

    public void doRender(JmeContext context) {
        context.getRenderer().draw(sceneRoot);
        context.getRenderer().renderQueue();
    }
}
